#ExtDNVoice- voice, ExtDNAM - am, ExtDNFax - fax, ExtDNNoAnswer - no answer, ExtDNBusy - busy
import random
def cpd_asm_load():
  numbers = [ExtDNVoice, ExtDNAM,  ExtDNNoAnswer, ExtDNBusy]
  maxCycle = 50
  maxSeizeAgent = 8
  maxMakeCall = 3
  timeoutConnect = 3
  i = 0
  CPD1.CPDReleaseAllAgents(ACD1, waitEvents = 0)
  CPD1.cpdServer.WaitAllEvents()
  LocalTserver.WaitAllEvents()

  try:
    for i in range (0, maxCycle ):

      for j in range (0, maxSeizeAgent ):
        CPD1.CPDSeizeAgent(ACD1, waitEvents = 0)
      time.sleep(1)

      for j in range (0, maxMakeCall):
        dest = random.choice(numbers)
        CPD1.CPDMakePredictiveCall(dest, waitEvents = 0)

      CPD1.cpdServer.WaitAllEvents(timeout = 2)
      LocalTserver.WaitAllEvents(timeout = 4)
   

      time.sleep(timeoutConnect) 

      for ag in LocalTserver.AgentList:
        LocalTserver.ReleaseCall(ag.dn.number)
      LocalTserver.WaitAllEvents()
      

  except KeyboardInterrupt:
    print "STOP"
    CPD1.CPDReleaseAllAgents(ACD1, waitEvents = 0)
    CPD1.cpdServer.WaitAllEvents()
    LocalTserver.WaitAllEvents()    
    return
    
  CPD1.cpdServer.WaitAllEvents()
  LocalTserver.WaitAllEvents()
  
def cpd_asm_load_no_ts():
  numbers = [ExtDNVoice, ExtDNAM,  ExtDNNoAnswer, ExtDNBusy]
  maxCycle = 5
  maxSeizeAgent = 60
  maxMakeCall = 60
  timeoutConnect = 15
  i = 0
  CPD1.CPDReleaseAllAgents(ACD1, waitEvents = 0)
  CPD1.cpdServer.WaitAllEvents()
  LocalTserver.WaitAllEvents()

  try:
    for i in range (0, maxCycle ):

      for j in range (0, maxSeizeAgent ):
        CPD1.CPDSeizeAgent(ACD1, waitEvents = 0)
      time.sleep(1)

      for j in range (0, maxMakeCall):
        dest = random.choice(numbers)
        CPD1.CPDMakePredictiveCall(dest, waitEvents = 0)

      CPD1.cpdServer.WaitAllEvents(timeout = 2)
      LocalTserver.WaitAllEvents(timeout = 4)
   

      time.sleep(timeoutConnect) 

      CPD1.CPDReleaseAllAgents(ACD1, waitEvents = 0)
      CPD1.cpdServer.WaitAllEvents()

      

  except KeyboardInterrupt:
    print "STOP"
    CPD1.CPDReleaseAllAgents(ACD1, waitEvents = 0)
    CPD1.cpdServer.WaitAllEvents()
    LocalTserver.WaitAllEvents()    
    return
    
  CPD1.cpdServer.WaitAllEvents()
  LocalTserver.WaitAllEvents()  
    